﻿using Student2024.Service;
using Student2024.UI.form;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student2024
{
    public partial class FormMain : Form
    { 
        //创建学生系统服务实例，用于数据库操作
        private StudentSystemService service = new StudentSystemService();
        public FormMain()
        {
            InitializeComponent();//初始化
        }

        /// <summary>
        /// 显示所有记录的事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAll_Click(object sender, EventArgs e)
        {
            var lst = service.GetAll();
            this.dataGridViewAllStudent.DataSource = lst;
        }

        /// <summary>
        /// 打开新高考记录界面的事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewExam_Click(object sender, EventArgs e)
        {
            string examType = "新高考";
            FormStudent frm = new FormStudent(examType);
            frm.ShowDialog();
        }

        /// <summary>
        /// 打开老高考界面的事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOldExam_Click(object sender, EventArgs e)
        {
            string examType = "老高考";
            FormStudent frm = new FormStudent(examType);
            frm.ShowDialog();
        }

        /// <summary>
        /// 点击btnAbout出现个人信息界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAbout_Click(object sender, EventArgs e)
        {
            FormAbout frm = new FormAbout();
            frm.ShowDialog();
        }

        /// <summary>
        /// 加载FormMain窗体的事件处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormMain_Load(object sender, EventArgs e)
        {
            FormLogin frm = new FormLogin();//实例化
            var result = frm.ShowDialog();
            if (result != DialogResult.OK)
            {
                //非正常登录
                this.Close();
            }
        }
    }
}
